using System.Collections.Generic;
using UnityEngine;

public class BtnTypeControlCar : MonoBehaviour
{
	public TypeControlCar selectType;

	public ToggleButton btnControlButton;

	public ToggleButton btnControlWheel;

	public ToggleButton btnControlAcceleration;

	private HUDControlAvto[] arrHUD;

	public GameObject controlsSettingsBlocker;

	private void Awake()
	{
		settings.typeControlerCar = ConvertIntToTypeControl(Load.LoadInt(settings.keyTypeControlCar));
		arrHUD = base.transform.root.GetComponentsInChildren<HUDControlAvto>(true);
		UpdateTypeControl();
		if (Load.LoadInt(settings.keyTypeControlCar) != Load.LoadInt("OldCarControll") && Load.LoadBool("NormalSession"))
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			dictionary.Add("Selected_Car_Mode", ConvertIntToTypeControl(Load.LoadInt(settings.keyTypeControlCar)).ToString());
			Save.SaveInt("OldCarControll", Load.LoadInt(settings.keyTypeControlCar));
			FlurryWrapper.LogEvent(FlurryWrapper.EV_CAR_CONTROL_TYPE, dictionary);
		}
	}

	private void OnEnable()
	{
		if (controlsSettingsBlocker != null)
		{
			if ((bool)PlayerBehavior.MyPlayer && (bool)PlayerBehavior.MyPlayer.currentCar && (PlayerBehavior.MyPlayer.currentCar.Type == CarType.Tank || PlayerBehavior.MyPlayer.currentCar.Type == CarType.Titan))
			{
				controlsSettingsBlocker.SetActive(true);
			}
			else
			{
				controlsSettingsBlocker.SetActive(false);
			}
		}
		UpdateTypeControl();
	}

	public void UpdateTypeControl()
	{
		if ((bool)PlayerBehavior.MyPlayer && (bool)PlayerBehavior.MyPlayer.currentCar && (PlayerBehavior.MyPlayer.currentCar.Type == CarType.Tank || PlayerBehavior.MyPlayer.currentCar.Type == CarType.Titan))
		{
			btnControlButton.IsActive = false;
			btnControlWheel.IsActive = true;
			btnControlAcceleration.IsActive = false;
			return;
		}
		selectType = ConvertIntToTypeControl(Load.LoadInt(settings.keyTypeControlCar));
		if (selectType == TypeControlCar.button)
		{
			btnControlButton.IsActive = true;
			btnControlWheel.IsActive = false;
			btnControlAcceleration.IsActive = false;
		}
		if (selectType == TypeControlCar.wheel)
		{
			btnControlButton.IsActive = false;
			btnControlWheel.IsActive = true;
			btnControlAcceleration.IsActive = false;
		}
		if (selectType == TypeControlCar.camera)
		{
			btnControlButton.IsActive = false;
			btnControlWheel.IsActive = false;
			btnControlAcceleration.IsActive = true;
		}
	}

	public void SetTypeControl(TypeControlCar val)
	{
		if ((bool)PlayerBehavior.MyPlayer && (bool)PlayerBehavior.MyPlayer.currentCar && (PlayerBehavior.MyPlayer.currentCar.Type == CarType.Tank || PlayerBehavior.MyPlayer.currentCar.Type == CarType.Titan))
		{
			return;
		}
		settings.typeControlerCar = val;
		Save.SaveInt(settings.keyTypeControlCar, ConvertTypeControlToInt(val));
		UpdateTypeControl();
		if (arrHUD != null && arrHUD.Length > 0)
		{
			HUDControlAvto[] array = arrHUD;
			foreach (HUDControlAvto hUDControlAvto in array)
			{
				hUDControlAvto.UpdateInterface();
			}
		}
	}

	public int ConvertTypeControlToInt(TypeControlCar val)
	{
		switch (val)
		{
		case TypeControlCar.button:
			return 0;
		case TypeControlCar.camera:
			return 1;
		case TypeControlCar.wheel:
			return 2;
		default:
			return 0;
		}
	}

	public static TypeControlCar ConvertIntToTypeControl(int val)
	{
		switch (val)
		{
		case 0:
			return TypeControlCar.button;
		case 1:
			return TypeControlCar.camera;
		case 2:
			return TypeControlCar.wheel;
		default:
			return TypeControlCar.camera;
		}
	}

	public void SetControlButton()
	{
		SetTypeControl(TypeControlCar.button);
	}

	public void SetControlCamera()
	{
		SetTypeControl(TypeControlCar.camera);
	}

	public void SetControlWheel()
	{
		SetTypeControl(TypeControlCar.wheel);
	}
}
